/**
 * Copyright(c) 2013 Jade Techonologies Co., Ltd.
 *
 * History:
 *   14-7-29 下午1:13 Created by dwzhang
 */
package com.jade.framework.base.comm.impl;

import java.util.List;

import com.jade.framework.base.comm.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 简单协议实现。
 *
 * @author dwzhang
 * @version 1.0 14-7-29 下午1:13
 */
public class SimpleProtocol implements Protocol
{
    //protected ConnectHandler connectHandler;
    //protected ErrorHandler errorHandler;
    //protected MessageHandler messageHandler;
    protected ProtocolHandler protocolHandler;
    protected MessageCodec messageCodec;
    protected ProtocolConfiguration configuration;
    protected List<ConnectionFilter> connectionFilters;

    protected Log log;

    public <T extends ProtocolHandler> T getProtocolHandler()
    {
        return (T) protocolHandler;
    }

    public void setProtocolHandler(ProtocolHandler protocolHandler)
    {
        this.protocolHandler = protocolHandler;
    }

    public MessageCodec getMessageCodec()
    {
        return messageCodec;
    }

    public void setMessageCodec(MessageCodec messageCodec)
    {
        this.messageCodec = messageCodec;
    }

    public ProtocolConfiguration getConfiguration()
    {
        return configuration;
    }

    public void setConfiguration(ProtocolConfiguration configuration)
    {
        this.configuration = configuration;
    }

    public List<ConnectionFilter> getConnectionFilters()
    {
        return connectionFilters;
    }

    public void setConnectionFilters(List<ConnectionFilter> connectionFilters)
    {
        this.connectionFilters = connectionFilters;
    }

    public ProtocolSession createSession(ProtocolTransport transport)
    {
        return new SimpleSession(this, transport);
    }

    public Log getLog()
    {
        if (log == null) {
            log = LogFactory.getLog(configuration.getName());
        }
        return log;
    }
}
